package com.durablemethods.tsmserver.home;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import com.google.appengine.api.rdbms.AppEngineDriver;

public class TeamsHome {
	
	public List<String> getTeamNames(){
		List<String> returnList = new ArrayList<String>();
		Connection c = null;
	      try {
	    	//printWriter.println("Register Driver - pre");
			DriverManager.registerDriver(new AppEngineDriver());
			//printWriter.println("Register Driver -- done -- getting connections");
			c = DriverManager.getConnection("jdbc:google:rdbms://durablemethods.com:duravest:tsm","jamie","catal0g");
			//printWriter.println("We have a connection");
			Statement s = c.createStatement();
			//printWriter.println("Executing Query -- pre");
			ResultSet rs = s.executeQuery("Select NAME from TEM_SPORTS.TEAMS ORDER BY NAME");
			while (rs.next()){
				String name = rs.getString("NAME");
				returnList.add(name);
			}
		} catch (SQLException e) {
			//printWriter.println("Error found");
			//printWriter.println(e.getMessage());
			e.printStackTrace();
		}
		return returnList;
	}

}
